<%-- 
    Document   : admin_khuyenmai
    Created on : Dec 27, 2013, 9:11:16 AM
    Author     : home
--%>

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page isErrorPage="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>

<t:layout_admin>
    <jsp:body>
        <c:if test="${param.error == 0}" >
            <script language="JavaScript">
            setTimeout("top.location.href = '<c:url value="/admin/khuyenmai/" />'", 0);
            </script>
        </c:if>

        <c:set var="promotion_start" value="${(ngayHienTai >= khuyenMai.getNgayBatDau()) && (ngayHienTai <= khuyenMai.getNgayKetThuc()) && (khuyenMai.getTinhTrangKhuyenMai() == 1)}" ></c:set>

            <link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/" />tabcontent.css" >
        <script type="text/javascript" src="<c:url value="/resources/js/" />tabcontent.js"></script>
        <script type="text/javascript" src="<c:url value="/resources/js/" />tiny_mce/tiny_mce.js"></script>
        <!--Tyni MCE-->
        <script type="text/javascript">
            tinyMCE.init({
                // General options
                mode: "textareas",
                theme: "advanced",
                plugins: "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks",
                // Theme options
                theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,visualblocks",
                theme_advanced_toolbar_location: "top",
                theme_advanced_toolbar_align: "left",
                theme_advanced_statusbar_location: "bottom",
                theme_advanced_resizing: true,
                // Replace values for the template plugin
                template_replace_values: {
                    username: "Some User",
                    staffid: "991234"
                }
            });
        </script>
        <!--TyniMCE-->
        <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td class="bgtitle">
                    <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                        <tr>
                            <td width="20">
                                <img src="<c:url value="/resources/images/" />mui_ten.gif" /></td>
                            <td valign="bottom" class="title">Danh sách sản phẩm khuyến mãi</td>
                            <td width="10" valign="bottom">&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>     
            <tbody>
                <tr>
                    <td valign="top">
                        <table width="100%" style="border-collapse: collapse" border="0" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
                        </table>
                        <br>
                        <!-- 3 menu cố định -->
                        <div id="pettabs" class="indentmenu">
                            <ul>
                                <li>
                                    <a href="#" rel="dog1" class="selected">
                                        <strong>Khuyến mãi</strong>
                                    </a>
                                </li>
                            </ul>
                            <br style="clear: left">
                        </div>

                        <!-- Chọn menu nào thì tab đó xuất hiện -->
                        <div style="border:1px solid #CCCCCC; width:960px; padding-bottom:0px; padding-left:0px; padding-right:0px; padding-top:0px;">
                            <!-- Dog 3, chèn nội dung vào đây --->
                            <div id="dog1" class="tabcontent" style="display: none;">

                                <!--Tạo khuyến mãi-->
                                <form name="promotionbytime" id = "promotionbytime" action="luu" method="post">
                                    <table width="400px" border="0" cellpadding="0" cellspacing="0" style="margin-top:15px; margin-left:15px">
                                        <tbody>
                                            <tr> 
                                                <td class="title16" style="width:130px; text-align: center">
                                                    <!-- Thay đổi ở đây -->
                                                    <strong>Khuyến mãi</strong>
                                                </td>
                                                <td style="width:65px; text-align: center">
                                                    <input type="radio" name="promotion_on_off" value="1" <c:if test="${promotion_start == true}">checked </c:if>>Có
                                                    </td>
                                                    <td>
                                                        <input type="radio" name="promotion_on_off" value="0" <c:if test="${promotion_start == false}">checked </c:if>>Không
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <img src="<c:url value="/resources/images/" />space.gif" height="10">
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <table width="400px" border="0" cellpadding="5" cellspacing="0" style="margin-left:15px">
                                        <tbody>
                                            <tr>
                                                <td width=200px>
                                                    <strong>Thời gian bắt đầu:</strong>
                                                </td>
                                                <td width=200px> 
                                                    <span>
                                                        <input type="text" name="datetimebegin" id="datetimebegin" value="${khuyenMai.getNgayBatDau()}">
                                                        <script>
                                                            $('#datetimebegin').datetimepicker({
                                                                currentText: "Hiện tại",
                                                                closeText: "Xong",
                                                                hourText: "Giờ",
                                                                minuteText: "Phút"
                                                            });
                                                        </script>
                                                    </span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <strong>Thời gian kết thúc:</strong>
                                                </td>
                                                <td>
                                                    <span>
                                                        <input type="text" name="datetimeend" id="datetimeend" value="${khuyenMai.getNgayKetThuc()}">
                                                        <script>
                                                            $('#datetimeend').datetimepicker({
                                                                currentText: "Hiện tại",
                                                                closeText: "Xong",
                                                                hourText: "Giờ",
                                                                minuteText: "Phút"
                                                            });
                                                        </script>
                                                    </span> 
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <strong>Phần trăm khuyến mãi:</strong>
                                                </td>
                                                <td>
                                                    <span>
                                                        <input type="text" name="percentdiscount" value="${khuyenMai.getPhanTram()}" maxlength="2">
                                                        <script>
                                                            $('#datetimend').datetimepicker({
                                                                currentText: "Hiện tại",
                                                                closeText: "Xong",
                                                                hourText: "Giờ",
                                                                minuteText: "Phút"
                                                            });
                                                        </script>
                                                    </span> 
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" style="text-align: center;">

                                                    <input type="submit" value="Lưu" name="submit" onclick="if (!checkdatetime())
                                                                return false;">
                                                    <script type="text/javascript">
                                                        function checkdatetime()
                                                        {
                                                            if (Date.parse(document.getElementById("datetimebegin").value) < Date.parse(document.getElementById("datetimeend").value))
                                                                return true;
                                                            alert("Thời gian kết thúc phải lớn hơn thời gian bắt đầu!");
                                                            return false;
                                                        }
                                                    </script>

                                                    <c:if test="${promotion_start == true}">
                                                        Đang diễn ra chương trình khuyến mãi
                                                    </c:if> 
                                                    <c:if test="${promotion_start == false}">
                                                        Hiện tại không có chương trình khuyến mãi
                                                    </c:if> 

                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </form>


                                <table width="100%" border="0" cellpadding="5" cellspacing="0"></table>
                            </div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>

        <script type="text/javascript">
            var mypets = new ddtabcontent("pettabs")
            mypets.setpersist(true)
            mypets.setselectedClassTarget("link")
            mypets.init(0)
        </script>
        <br>

    </jsp:body>
</t:layout_admin>